package ooday04;

public class Test {
    public static void main(String[] args) {


        Animal z = new Animal("zhangsan",15,"白色"){
            @Override
            void eat() {

            }
        };
Master master = new Master();

        Animal[] animal = new Animal[5];
        animal[0] = new Dog("小红", 2, "红色");
        animal[1] = new Dog("小黄", 3, "黄色");
        animal[2] = new Chick("鸡", 1, "白色");
        animal[3] = new Chick("鸡仔", 1, "黄色");
        animal[4] = new Fish("小鲤鱼",1,"红色");

        for (int i = 0; i < animal.length ; i++) {
            System.out.println(animal[i].name);
            System.out.println(animal[i].age+"岁了");
            animal[i].eat();
            animal[i].drink();
            if (animal[i] instanceof Dog){
                Dog dog  = (Dog)animal[i];
                dog.lookHome();
            }
            if (animal[i] instanceof Chick){
                Chick chick = (Chick)animal[i];
                chick.layEggs();
            }
            if (animal[i] instanceof Swim){//若能游泳
                Swim s = (Swim) animal[i];
                s.swim();
            }

        }


      /*

       // Animal animal = new Dog("狗腿子",2,"白色");
        Animal dog = new Dog("狗腿子",2,"白色");
        Fish fish = new Fish("小鲤鱼",2,"金色");
        Chick chick = new Chick("鸡仔",1,"黄色");
        Master master = new Master();
        master.feed(dog);//传参的同时,系统自动做了向上造型
        master.feed(chick);
        master.feed(fish = new Fish("小鲤鱼",2,"金色"));
*/


        /*Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小红", 2, "红色");
        System.out.println(dogs[0].name);
        dogs[1] = new Dog("小白", 2, "白色");
        dogs[2] = new Dog("小黄", 3, "黄色");
        System.out.println(dogs[1].age);
        for (int i = 0; i < dogs.length; i++) {
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }
        Chick[] chick = new Chick[2];
        chick[0] = new Chick("鸡", 1, "白色");
        chick[1] = new Chick("鸡仔", 1, "黄色");
        for (int i = 0; i < chick.length; i++) {
            System.out.println(chick[i].name);
            chick[i].layEggs();
        }
        Fish[] fish = new Fish[2];
        fish[0] = new Fish("小鲤鱼",1,"红色");
      //  fish[1] = null;//表示空,没有指向任何对象
     ///   System.out.println(fish[1].name);//语法不报错,但是不能访问
*/


    }
}
